﻿
@page
@model AdminUI.Pages.SysManage.RoleModel
@{
    var F = Html.F();
}

@section body {
    <f:Panel ID="Panel1" BodyPadding="5" ShowBorder="false" Layout="VBox" ShowHeader="false" IsViewPort="true">
        <Items>
            <f:Grid ID="Grid1" BoxFlex="1" ShowBorder="true" ShowHeader="false" EnableTextSelection="true" EnableColumnLines="true" EnableCheckBoxSelect="true" EnableMultiSelect="false" AllowSorting="true" AllowPaging="true" IsDatabasePaging="true"
                    DataIDField="RoleID" DataTextField="RoleName" SortField="RoleID" SortDirection="DESC" PageSize="@ViewBag.PageSize" RecordCount="@ViewBag.Total" DataSource="@ViewBag.DataSource"
                    OnSort="@Url.Handler("Grid_DoAction")" OnSortFields="Panel1" OnPageIndexChanged="@Url.Handler("Grid_DoAction")" OnPageIndexChangedFields="Panel1">
                <Toolbars>
                    <f:Toolbar ID="Toolbar1" ToolbarAlign="Right" ItemSpace="1">
                        <Items>
                            <f:Button ID="btnAdd" IconAlign="Left" EnableDefaultState="false" IconFont="_Plus" Text="新增" OnClientClick="onAddClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnEdit" IconAlign="Left" EnableDefaultState="false" IconFont="_Edit" Text="编辑" OnClientClick="onEditClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnDelete" IconAlign="Left" EnableDefaultState="false" IconFont="TrashO" Text="删除" OnClientClick="onDeleteClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnAuthorize" IconAlign="Left" EnableDefaultState="false" IconFont="Lock" Text="授权" OnClientClick="onAuthorizeClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnChangeEnableUsers" IconAlign="Left" EnableDefaultState="false" IconFont="_Tag" Text="状态">
                                <Menu>
                                    <f:MenuButton ID="btnEnableUsers" Text="启用" OnClientClick="onEnableClick();"></f:MenuButton>
                                    <f:MenuButton ID="btnDisableUsers" Text="禁用" OnClientClick="onDisableClick();"></f:MenuButton>
                                </Menu>
                            </f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnRefresh" IconAlign="Left" EnableDefaultState="false" IconFont="_Refresh" Text="刷新" OnClientClick="onRefreshClick();"></f:Button>
                            <f:ToolbarFill ID="ToolbarFill1"></f:ToolbarFill>
                            <f:DropDownList ID="ddlCondition" SelectedValue="" Width="150">
                                <f:ListItem Text="== 请选择条件 ==" Value="" />
                                <f:ListItem Text="角色ID" Value="RoleID" />
                                <f:ListItem Text="角色名称" Value="RoleName" />
                            </f:DropDownList>
                            <f:TriggerBox ID="ttbSearch" ShowLabel="false" EmptyText="请输入搜索关键字" TriggerIcon="Search" OnTriggerClick="@Url.Handler("Grid_DoAction")" OnTriggerClickFields="Panel1"
                                          OnTriggerClickParameter1="@(new Parameter("actionType", "search", ParameterMode.String))"
                                          OnTriggerClickParameter2="@(new Parameter("searchText", "F.ui.ttbSearch.getValue()"))"
                                          OnTriggerClickParameter3="@(new Parameter("searchCondition", "F.ui.ddlCondition.getValue()"))">
                            </f:TriggerBox>
                        </Items>
                    </f:Toolbar>
                </Toolbars>
                <Columns>
                    <f:RowNumberField HeaderText="#" TextAlign="Center" />
                    <f:RenderField HeaderText="角色ID" DataField="RoleID" FieldType="Int" QuickSortField="true" Width="100" TextAlign="Center" />
                    <f:RenderField HeaderText="角色名称" DataField="RoleName" Width="150" />
                    <f:RenderField HeaderText="角色类型" DataField="RoleType" FieldType="Int" RendererFunction="renderType" Width="80" TextAlign="Center" />
                    <f:RenderCheckField HeaderText="启用" DataField="IsEnable" RenderAsStaticField="true" Width="80" TextAlign="Center" />
                    <f:RenderField HeaderText="备注" DataField="Memo" Width="200" ExpandUnusedSpace="true" />
                </Columns>
                <PageItems>
                    <f:ToolbarSeparator></f:ToolbarSeparator>
                    <f:ToolbarText Text="每页记录数："></f:ToolbarText>
                    <f:DropDownList ID="ddlGridPageSize" Width="60" SelectedValue="@ViewBag.PageSize" OnSelectedIndexChanged="@Url.Handler("Grid_DoAction")" OnSelectedIndexChangedParameter1="@(new Parameter("actionType","changePageSize",ParameterMode.String))" OnSelectedIndexChangedFields="Panel1">
                        <Items>
                            <f:ListItem Text="10" Value="10"></f:ListItem>
                            <f:ListItem Text="20" Value="20"></f:ListItem>
                            <f:ListItem Text="30" Value="30"></f:ListItem>
                            <f:ListItem Text="50" Value="50"></f:ListItem>
                        </Items>
                    </f:DropDownList>
                </PageItems>
            </f:Grid>
        </Items>
    </f:Panel>

    <f:Window ID="Window1" IsModal="true" Hidden="true" Target="Top" EnableResize="true" EnableMaximize="true" EnableIFrame="true" Width="400" Height="400">
        @*<Listeners>
            <f:Listener Event="close" Handler="onWindowClose('refresh');"></f:Listener>
        </Listeners>*@
    </f:Window>
}

@section script {
    <script src="~/res/js/grid.js"></script>
    <script>
        function onAddClick(event) {
            var path = "/SysManage/RoleAdd";
            F.ui.Window1.show(path, '新增角色');
        }

        function onEditClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要修改的记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/SysManage/RoleEdit?id=" + selectedRow;
            F.ui.Window1.show(path, '编辑角色');
        }

        function onAuthorizeClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要授权的角色！');
                return;
            }

            var selectedRow = grid1.getSelectedRow(true).values;//返回行数据
            //showNotify(F.toJSON(selectedRow));
            var path = "/SysManage/RoleAuthorize?roleId=" + selectedRow.RoleID + "&menuType=" + selectedRow.RoleType;
            //showNotify(path);
            F.ui.Window1.show(path, '角色授权', 360, 600);
        }

        function onDeleteClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要删除的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要删除所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        actionType: 'delete',
                        selectedIDs: selectedRows
                    });
                }
            });
        }

        function onEnableClick() {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要启用的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要启用所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        actionType:'enable',
                        selectedIDs: selectedRows
                    });
                }
            });
        }

        function onDisableClick() {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要禁用的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要禁用所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        actionType:'disable',
                        selectedIDs: selectedRows
                    });
                }
            });
        }

        function onRefreshClick() {
            var grid1 = F.ui.Grid1;
            var selectedRows = grid1.getSelectedRows();
            F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                actionType: 'refresh',
                selectedIDs: selectedRows
            });
        }

        //角色类型：1-平台，2-运营，3-门店
        function renderType(value, params) {
            switch (value) {
                case 1:
                    return "<span class='tag-c1'>平台</span>";
                case 2:
                    return "<span class='tag-c3'>租户</span>";
                case 3:
                    return "<span class='tag-c5'>门店</span>";
                default:
                    return "-";
            }
        }

    </script>
}